//
//  MainTabbar.swift
//  Weibo
//
//  Created by 明丽 on 16/1/10.
//  Copyright © 2016年 明丽. All rights reserved.
//

import UIKit

class MainTabbar: UITabBar {
//重写tabbar系统的没法满足我们的需求,系统的只能读,没法直接修改,我们需要重写
    override init(frame: CGRect) {
        super.init(frame: frame)
        addSubview(plusBtn)
        
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //创建视图的大小
    override func layoutSubviews() {
        super.layoutSubviews()
        let w = self.bounds.width/5
        let h = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        //定义索引
        var index: CGFloat = 0

        //获取所有的子视图
        for sb in subviews{
            if sb.isKindOfClass(NSClassFromString("UITabBarButton")!){
               sb.frame = CGRectOffset(rect, index * w, 0)
                
                if index == 1{
                index++
                
                }
                index++
                
                
            }}
        
        plusBtn.frame=CGRectOffset(rect, 2 * w, 0)
        
        }
        //懒加载button
//    lazy var plusBtn: UIButton = {
//    let btn = UIButton()
//        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
//        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Selected)
//        //设置按钮图片
//        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState:.Selected)
//        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState:.Normal)
//        btn.sizeToFit()
//        return btn
//        
//        
//        }()
    lazy var plusBtn: UIButton = UIButton(imageName: "tabbar_compose_icon_add", backImageName: "tabbar_compose_button")
    
        

    
}
